using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    class MRPRequirementTypesService 
    {
        ISession session;

        public MRPRequirementTypesService(ISession session)
        {
            this.session = session;
        }
        public MRPRequirementTypesService( )
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrprequirementtypes(MRPRequirementTypes mrprequirementtypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrprequirementtypesX);
            tx.Commit();
        }

        public void UpdateMrprequirementtypes(MRPRequirementTypes mrprequirementtypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrprequirementtypesX);
            tx.Commit();
        }

        public void DeleteMrprequirementtypes(MRPRequirementTypes mrprequirementtypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrprequirementtypesX);
            tx.Commit();
        }

        public IList<MRPRequirementTypes> GetAllMrprequirementtypes(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPRequirementTypes");
            IList<MRPRequirementTypes> list = query.List<MRPRequirementTypes>();
            if (evict)
            {
                foreach (MRPRequirementTypes s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPRequirementTypes GetAllMrprequirementtypesByID(String id,Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPRequirementTypes as c where c.Requirementtypecode= :x");
            query.SetString("x", id);
            MRPRequirementTypes s = (MRPRequirementTypes)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPRequirementTypes> GetMrprequirementtypesByQuery(IQuery query,Boolean evict)
        {
            IList<MRPRequirementTypes> list = query.List<MRPRequirementTypes>();
            if (evict)
            {
                foreach (MRPRequirementTypes s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
